<template>
  <ContentWrap>
    <el-form :model="queryParams" ref="queryFormRef" label-width="auto" :inline="true">
      <el-form-item label="项目名称" prop="projectType">
        <el-select v-model="queryParams.projectId" placeholder="请输入项目名称" :clearable="true">
          <el-option
            v-for="dict in projectList"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="版本号" prop="version">
        <el-input v-model="queryParams.version" placeholder="请输入版本号" :clearable="true" />
      </el-form-item>
      <el-form-item label="版本内容" prop="versionContent">
        <el-input
          v-model="queryParams.versionContent"
          placeholder="请输入版本内容"
          :clearable="true"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="queryParams.remark" placeholder="请输入备注" :clearable="true" />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleClickSearch">
          <Icon icon="ep:search" />
          搜索
        </el-button>
        <el-button @click="handleClickReset">
          <Icon icon="ep:refresh" />
          重置
        </el-button>
        <el-button @click="handleClickCreate"> 新建 </el-button>
      </el-form-item>
    </el-form>
    <Table
      :columns="columns"
      :page-param="queryParams"
      :adaptive="true"
      :page-data="queryData"
      save-key="DevopsProjectVersion"
      height-per="90"
      @page-change="getPage"
      @row-dblclick="handleTableDblclick"
    >
      <template #menu="{ row }">
        <context-menu-item label="修改" @click="handleClickChange(row)" v-hasPermi="['']" />
        <context-menu-item label="删除" @click="handleClickDelete(row)" v-hasPermi="['']" />
      </template>
    </Table>
  </ContentWrap>
  <DevopsProjectVersionEdit ref="projectVersionEditRef" @success="getPage()" />
</template>
<script setup name="DevopsProjectVersion" lang="ts">
import * as DevopsProjectVersionApi from '@/api/infra/devops/projectVersion'
import * as DevopsProjectApi from '@/api/infra/devops/project'
import DevopsProjectVersionEdit from './DevopsProjectVersionEdit.vue'
const projectVersionEditRef = ref()
const queryFormRef = ref()
const projectList = ref()
const queryParams = ref({
  projectId: undefined,
  version: undefined,
  versionContent: undefined,
  remark: undefined
})
const queryData = ref()
const columns = [
  {
    label: '项目名称',
    prop: 'project.name'
  },
  {
    label: '版本号',
    prop: 'version'
  },
  {
    label: '版本内容',
    prop: 'versionContent'
  },
  {
    label: '备注',
    prop: 'remark'
  },
  {
    label: '创建时间',
    prop: 'createTime'
  },
  {
    label: '更新时间',
    prop: 'updateTime'
  }
]
/** 初始化 */
onMounted(async () => {
  projectList.value = await DevopsProjectApi.listQuery()
  getPage()
})

/** 搜索按钮操作 */
const handleClickSearch = () => {
  getPage()
}

/** 重置按钮操作 */
const handleClickReset = () => {
  queryFormRef.value?.resetFields()
  handleClickSearch()
}

/** 新建按钮操作 */
const handleClickCreate = () => {
  projectVersionEditRef.value.open('create', 0)
}

/** 处理响应事件  */
const getPage = async () => {
  queryData.value = await DevopsProjectVersionApi.pageQuery(queryParams.value)
}

/** 处理table行双击事件 */
const handleTableDblclick = (row) => {
  projectVersionEditRef.value.open('update', row.id)
}

/** 处理右击事件 修改 */
const handleClickChange = (row) => {
  projectVersionEditRef.value.open('update', row.id)
}

/** 处理右击事件 删除 */
const handleClickDelete = async (row) => {
  await DevopsProjectVersionApi.deleted(row.id)
  getPage()
}
</script>
